from django.db import models

# Create your models here.


from django.db import models
from django.utils.translation import ugettext_lazy as _

# 获得基本用户模型类
from django.contrib.auth import get_user_model

User = get_user_model()


class Profile(models.Model):
    mobile = models.CharField(verbose_name='电话号码', max_length=11, unique=True, db_index=True, null=True, blank=True)
    user = models.ForeignKey(User, verbose_name='用户', on_delete=models.CASCADE, related_name='profile')  # 在profile里面
    pass


class Article(models.Model):
    """Article Model"""
    STATUS_CHOICES = (
        ('p', _('Published')),  # 第一个是数据库存的和前端交互的，第二个三admin展示的序列化展示的
        ('d', _('Draft')),)

    title = models.CharField(verbose_name=_('Title (*)'), max_length=90, db_index=True)  # 建立索引
    body = models.TextField(verbose_name=_('Body'), blank=True)
    author = models.ForeignKey(User, verbose_name=_('Author'), on_delete=models.CASCADE,
                               related_name='articles')  # related_name 反响映射
    status = models.CharField(verbose_name=_('Status (*)'), max_length=1, choices=STATUS_CHOICES, default='s',
                              null=True, blank=True)
    create_date = models.DateTimeField(verbose_name=_('Create Date'), auto_now_add=True)

    liked_by = models.ManyToManyField(to=User)

    def __str__(self):
        return self.title

    class Meta:
        ordering = ['-create_date']
        verbose_name = "Article"
        verbose_name_plural = "Articles"
